
package br.com.moxeon.model.cash;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.moxeon.model.MoxeonControlledPersistentEntity;
import br.com.moxeon.model.enums.TypeThrowItem;
import br.com.moxeon.model.enums.TypeThrowTransaction;
import br.com.moxeon.model.financialaccounts.FinancialAccount;
import br.com.moxeon.model.financialitems.Check;
import br.com.moxeon.model.financialitems.FinancialItem;
import br.com.vexillum.util.Return;


@SuppressWarnings("serial")
@Entity
@Table(name = "throw")
public class Throw extends MoxeonControlledPersistentEntity {
	
	@OneToOne(targetEntity = FinancialItem.class, fetch = FetchType.LAZY)
	@Cascade(value={CascadeType.SAVE_UPDATE, CascadeType.MERGE})
	@JoinColumn(name = "financial_item")
	private FinancialItem item;
	
	@Enumerated
	@Column(nullable = false, name="type_throw_transaction")
	private TypeThrowTransaction type;
	
	/*
	@Deprecated
	@ManyToOne(targetEntity = OpeningCash.class, fetch = FetchType.LAZY)
	@JoinColumn(nullable = false, name = "opening_cash_id")
	private OpeningCash openingCash;
	*/
	
	private String observation;
	
	@Column(nullable = false)
	private Double value;
	
	@Column(nullable = true)
	private Date throwDate;
	
	@Enumerated
	private TypeThrowItem typeThrowItem;
	
	@ManyToOne(targetEntity = ThrowType.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "throw_type_id")
	private ThrowType throwType;
	
	@ManyToOne(targetEntity = FinancialAccount.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "financial_account_id")
	private FinancialAccount financialAccount;
	
	@ManyToOne(targetEntity = ThrowOperation.class, fetch = FetchType.LAZY)
	@Cascade(value={CascadeType.SAVE_UPDATE, CascadeType.MERGE})
	@JoinColumn(name = "operation_id")
	private ThrowOperation operation;

	public FinancialItem getItem() {
		return item;
	}

	public TypeThrowTransaction getType() {
		return type;
	}

	/*
	public OpeningCash getOpeningCash() {
		return openingCash;
	}
	
	public void setOpeningCash(OpeningCash openingCash) {
		this.openingCash = openingCash;
	}
	*/

	public Double getValue() {
		return value;
	}

	public Date getThrowDate() {
		return throwDate;
	}

	public TypeThrowItem getTypeThrowItem() {
		return typeThrowItem;
	}

	public ThrowType getThrowType() {
		return throwType;
	}

	public FinancialAccount getFinancialAccount() {
		return financialAccount;
	}

	public ThrowOperation getOperation() {
		return operation;
	}

	public void setItem(FinancialItem item) {
		this.item = item;
	}

	public void setType(TypeThrowTransaction type) {
		this.type = type;
	}

	public void setValue(Double value) {
		this.value = value;
	}

	public void setThrowDate(Date throwDate) {
		this.throwDate = throwDate;
	}

	public void setTypeThrowItem(TypeThrowItem typeThrowItem) {
		this.typeThrowItem = typeThrowItem;
	}

	public void setThrowType(ThrowType throwType) {
		this.throwType = throwType;
	}

	public void setFinancialAccount(FinancialAccount financialAccount) {
		this.financialAccount = financialAccount;
	}

	public void setOperation(ThrowOperation operation) {
		this.operation = operation;
	}

	public String getObservation() {
		return observation;
	}

	public void setObservation(String observation) {
		this.observation = observation;
	}
	
	public String getFormatedFinancialItem()
	{
		if (getTypeThrowItem() == TypeThrowItem.CHEQUE)
			return TypeThrowItem.CHEQUE.getDesc() + " - " + ((Check) item).getNumber();
		if (getTypeThrowItem() == TypeThrowItem.CHEQUE)
			return TypeThrowItem.DINHEIRO.getDesc();
		return "";
	}

}